using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Resources;
using System.IO;
using System.Xml;
using System.Reflection;

namespace SilverlightSnoop
{

    public class XapAssemblyType
    {
        private XapAssembly _XapAsm;

        private Type _Type;
        public Type Type
        {
            get
            {
                return _Type;
            }
        }

        public string Name
        {
            get { return Type.FullName; }

        }

        /// <summary>
        /// Initializes a new instance of the XapAssemblyType structure.
        /// </summary>
        /// <param name="type"></param>
        public XapAssemblyType(Type type, XapAssembly asm)
        {
            _XapAsm = asm;
            _Type = type;
        }

        public UIElement GetNewTypeInstance()
        {
            List<String> resourceDictLocations = new List<string>();

            //var app = Activator.CreateInstance(_XapAsm.bootStrapApp);

            AGHikariInjector.AppHost host = new AGHikariInjector.AppHost();

            foreach (var item in _XapAsm.MergedAppLevelDictionaries)
            {
                Application.Current.Resources.MergedDictionaries.Add(item);
            }

            _XapAsm.MergedAppLevelDictionaries.Clear();

            host.Boot(Type);

            return host;
        }
    }
}
